package com.leal.hive;

import com.leal.util.YamlUtil;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.thrift.TException;

import java.util.LinkedHashMap;

/**
 * @Classname bigdata
 * @Description 使用metastore client 获得hive相关信息
 * @Date 2023/8/7 15:51
 * @Created by leal
 */
public class MetaInfo {
    private HiveMetaStoreClient hiveMetaStoreClient;

    public HiveMetaStoreClient getHiveMetaStoreClient() {
        return hiveMetaStoreClient;
    }

    public void setHiveMetaStoreClient(String mode) {
        try {
            HiveConf hiveConf = new HiveConf();
            System.out.println(YamlUtil.getEnvInfo(mode, "config.yaml").get("metastore"));
            hiveConf.set("hive.metastore.uris", YamlUtil.getEnvInfo(mode, "config.yaml").get("metastore"));
            this.hiveMetaStoreClient = new HiveMetaStoreClient(hiveConf);
            //当前版本2.3.4与集群3.0版本不兼容，加入此设置
            this.hiveMetaStoreClient.setMetaConf("hive.metastore.client.capability.check", "false");
        } catch (MetaException ex) {
            ex.printStackTrace();
        } catch (TException e) {
            throw new RuntimeException(e);
        }
    }
}
